using System;
using System.Net.NetworkInformation;

// 抽象产品
public interface IAbstractProduct
{
    void Use();
}

// 具体产品1
public class ConcreteProduct1 : IAbstractProduct
{
    public void Use()
    {
        Console.WriteLine("Using ConcreteProduct1");
    }
}

// 具体产品2
public class ConcreteProduct2 : IAbstractProduct
{
    public void Use()
    {
        Console.WriteLine("Using ConcreteProduct2");
    }
}

// 抽象工厂
public interface IAbstractFactory
{
    IAbstractProduct CreateProduct1();
    IAbstractProduct CreateProduct2();
}

// 具体工厂1
public class ConcreteFactory1 : IAbstractFactory
{
    public IAbstractProduct CreateProduct1()
    {
        return new ConcreteProduct1();
    }

    public IAbstractProduct CreateProduct2()
    {
        return new ConcreteProduct2();
    }
}

// 具体工厂2
public class ConcreteFactory2 : IAbstractFactory
{
    public IAbstractProduct CreateProduct1()
    {
        // 可以返回不同的ConcreteProduct1的实现
        return new ConcreteProduct1();
    }

    public IAbstractProduct CreateProduct2()
    {
        // 可以返回不同的ConcreteProduct2的实现
        return new ConcreteProduct2();
    }
}

// 客户端代码
public class Client
{
    public void ClientCode(IAbstractFactory factory)
    {
        IAbstractProduct product1 = factory.CreateProduct1();
        IAbstractProduct product2 = factory.CreateProduct2();

        product1.Use();
        product2.Use();
    }
}

// 程序入口
class Program
{
    static void Main(string[] args)
    {
        Client client = new Client();

        // 使用具体工厂1
        IAbstractFactory factory1 = new ConcreteFactory1();
        client.ClientCode(factory1);

        // 使用具体工厂2
        IAbstractFactory factory2 = new ConcreteFactory2();
        client.ClientCode(factory2);
    }
}
//输出结果
//Using ConcreteProduct1
//Using ConcreteProduct2
//Using ConcreteProduct1
//Using ConcreteProduct2